<template>
  <div id="my-privacy-agreement">
    <el-checkbox v-model="isAgree"></el-checkbox>
    <span @click="openMyPrivacyAgreementDialog">是否同意《可可商城店铺手机端-隐私协议》</span>
    <my-privacy-agreement-dialog ref="my-privacy-agreement-dialog"/>
  </div>
</template>

<script>
import MyPrivacyAgreementDialog from './MyPrivacyAgreementDialog'
export default {
  name: 'MyPrivacyAgreement',
  components: {MyPrivacyAgreementDialog},
  props: {
    callback:Function
  },
  data:function(){
    return {
      isAgree:false
    }
  },
  watch:{
    isAgree:function () {
      if (typeof this.$props.callback){
        this.$props.callback(this.isAgree)
      }
      if (this.isAgree){
        localStorage.setItem("MyPrivacyAgreement","1")
      }
    }
  },
  mounted () {
    localStorage.removeItem("MyPrivacyAgreement")

    let $this=this
    $this.bus.$on('MyPrivacyAgreementCallBus',function () {
      if (localStorage.getItem("MyPrivacyAgreement")==='1'){
        $this.isAgree=true
      } else{
        $this.isAgree=false
      }
      $this.$forceUpdate()
    })
  },
  methods:{
    openMyPrivacyAgreementDialog:function () {
      this.$refs['my-privacy-agreement-dialog'].open()
    }
  }
}
</script>

<style scoped>
  #my-privacy-agreement{ display: inline-block;}
  #my-privacy-agreement{}
</style>
